<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情页</title>
    <link rel="stylesheet" href="./css/detail.css">
    <link rel="stylesheet" href="./css/normal.css">
</head>

<body>
    <div class="nav">
        <img src="./pic/dog.png" alt="">
        <span class="blog_title">我的博客系统</span>
        <span class="space"></span>
        <a href="./blog_list.html" class="nav_span">主页</a>
        <a href="./edit.html" class="nav_span">写博客</a>
        <a href="reg.html" class="nav_span">注册</a>
        <a onclick="logout()" class="nav_span">注销</a>
    </div>

    <div class="container">
        <div class="left">
            <div class="card">
                <img src="./pic/src.jpg" alt="">

                <h3></h3>
                <a href="">Github地址</a>
                <div class="row">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="row">
                    <span>2</span>
                    <span>1</span>
                </div>
            </div>
        </div>

        <div class="right">
            <div class="content">
                <div class="title"></div>
                <div class="date"></div>
                <div class="detail" id="content">

                </div>
                <div class="operating">
            
                </div>
            </div>
        </div>
    </div>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="editormd/lib/marked.min.js"></script>
    <script src="editormd/lib/prettify.min.js"></script>
    <script src="editormd/editormd.js"></script>
    <script src="./js/common.js"></script>

    <script>

        $.ajax({
            type: "get",
            url: "/blog/getblog" + location.search,
            success: function (result) {
                if (result.code == 200 && result.data != null) {
                    $(".title").html(result.data.title);
                    $(".date").html(result.data.createTime);
                    editormd.markdownToHTML("content", {
                        markdown: result.data.content
                    });
                    
                    if(result.data.loginUser==1){
                        var finalHtml = "";
                        finalHtml += '<button onclick="window.location.href=\'update.html'+location.search+'\'">编辑</button>';
                        finalHtml += '<button onclick="deleteBlog()">删除</button>';
                        $(".operating").html(finalHtml);
                    }
                }
            },
            error:function(error){
                if(error!=null && error.status==401){
                    alert("用户未登录, 请先登录");
                    location.href = "login.html";
                }
            }
        })
        var url = "/user/getauthorinfo"+location.search;
        getUserInfo(url);
        function deleteBlog(){
            $.ajax({
                type:"post",
                url: "/blog/delete"+location.search,
                success:function(result){
                    console.log(result);
                    if(result.code==200 && result.data==true){
                        alert("博客删除成功");
                        location.href ="blog_list.html";
                    }
                }
            });
        }


    </script>
</body>

</html>